package com.yuzhong.topic;

import com.hdy.framework.struts2.action.BaseAction;
import com.yuzhong.common.tree.AbstractTree;
import com.yuzhong.common.tree.TreeNode;
import com.yuzhong.topic.dto.TopicDto;
//http://127.0.0.1/ssh/topic/in.action
public class TopicAction extends BaseAction{
	private static final long serialVersionUID = -7157651261001683783L;
	private TreeNode root;
	@Override
	public String execute() {
		//根
		root = new TreeNode();
		root.setNodeData(this.buildTopic(0L, "根", 0L, 0, 0L));
		//第一层栏目
		TopicDto n1 = this.buildTopic(1L, "栏目A1", 0L, 1, 0L);
		AbstractTree noden1 = new TreeNode(n1);
		TopicDto n2 = this.buildTopic(2L, "栏目A2", 0L, 1, 0L);
		AbstractTree noden2 = new TreeNode(n2);
		root.addChildNode(noden1);
		root.addChildNode(noden2);
		//第二层栏目
		TopicDto n11 = this.buildTopic(3L, "栏目A11", 1L, 2, 0L);
		AbstractTree noden11 = new TreeNode(n11);
		TopicDto n21 = this.buildTopic(4L, "栏目A21", 2L, 3, 0L);
		AbstractTree noden21 = new TreeNode(n21);
		TopicDto n22 = this.buildTopic(5L, "栏目A22", 2L, 3, 0L);
		AbstractTree noden22 = new TreeNode(n22);
		noden1.addChildNode(noden11);
		noden2.addChildNode(noden21);
		noden2.addChildNode(noden22);
		//第三层栏目
		TopicDto n111 = this.buildTopic(6L, "栏目A111", 3L, 4, 0L);
		AbstractTree noden111 = new TreeNode(n111);
		noden11.addChildNode(noden111);
		return SUCCESS;
	}
	private TopicDto buildTopic(Long id,String name,Long parentId,int deepth,Long rootId){
		TopicDto root = new TopicDto();
		root.setId(id);
		root.setName(name);
		root.setParentId(parentId);
		root.setDeepth(deepth);
		root.setRootId(rootId);
		return root;
	}
	public TreeNode getRoot() {
		return root;
	}
	public void setRoot(TreeNode root) {
		this.root = root;
	}
}
